
<?php
ob_clean();

$id = $_GET['id'];

//ajax发送删除确认请求
if(!empty($_SERVER['HTTP_X_REQUESTED_WITH'])){
/*
  $sql = "select * from `cate` where pid=$id";//查询是否有子级

  $result = mysqli_query($link,$sql);*/

  $result = getSelectByOne('cate',"pid=$id");

  echo !empty($result)?1:0;die;

}


$row = getCateDel($id);


if($row>0){
   echo"<script>alert('分类删除成功');location.href='index.php?c=cate&a=list&admin=1'</script>";die;
}else{
   echo"<script>alert('分类删除失败');history.go(-1)</script>";die;
}

function getCateDel($pid=0){

  $sql = "select * from `cate` where pid=$pid ";

  $result = mysqli_query($GLOBALS['link'],$sql);

  //先说明有子级
  if($result->num_rows>0){

    while ($arr=mysqli_fetch_assoc($result)){

        getCateDel($arr['id']);

    }
  }

  return del($GLOBALS['c'],$pid);//调用删除函数

}


